<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<div class='resource-selector'>
	<div id='items'>
		<s:include value="resources-tile.jsp"></s:include>
	</div>
	<div class='clear''></div>
	<div id="pager" class="pager span-16 separator"></div>
</div>
<script type="text/javascript">
$("#pager").pager({ 
	pagenumber: 1, 
	pagecount: <s:property value="pagingItems.totalPages"/>, 
	buttonClickCallback: loadPage, 
	firstLabel: "首页", 
	prevLabel: "前一页", 
	nextLabel: "下一页", 
	lastLabel: "末页" });

function loadPage(number) {
	loadPage(number, null);
}

function loadPage(number, callback) {
	$("#items").html("<span>loading...</span>");
    var limit = <s:property value="pagingItems.option.limit"/>;
    var offset = (number - 1) * limit;
    var q = "type=1&option.limit=" + limit + "&option.offset=" + offset;
    var url = "selecting-theme.action";
	$.ajax({
		url: url,
		data: q,
		type: 'POST',
		success: function(data) {
			$("#items").html(data);
			var pageCount = parseInt($(".resource-list").attr("pages"));
			$("#pager").pager({ pagenumber: number, pagecount: pageCount, buttonClickCallback: loadPage, firstLabel: "首页", prevLabel: "前一页", nextLabel: "下一页", lastLabel: "末页" });
			if (callback)
			{
				callback();
			}
		}
	});
}

function reload()
{
	reload(null);
}

function reload(callback)
{
	var i = parseInt($(".resource-list").attr("pageIndex"));
	loadPage(i+1, callback);
}
</script>
